package figure8.GUI;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;

//Window to allow you to customise the program and it's features
public class CustomiseWindow extends JFrame {
	private static int themeVal;
	private static int exitVal;
	
	public CustomiseWindow(final MainWindow mainWin)
	{
		final CustomiseWindow window = this;
		this.setTitle("Customise Preferences");
		this.setLayout(new GridLayout(5, 2, 5, 5));
		JLabel theme = new JLabel("Change theme:");
		final JComboBox selectTheme = new JComboBox();
		selectTheme.addItem("Default");
		selectTheme.addItem("Dark");
		selectTheme.addItem("Light");
		switch (themeVal) {
		  case 0: 
			  selectTheme.setSelectedIndex(0);
		    break;
		  case 1: 
			  selectTheme.setSelectedIndex(1);
		    break;
		  case 2: 
			  selectTheme.setSelectedIndex(2);
		    break;
		  default: 
			  selectTheme.setSelectedIndex(0);
		}
		this.add(theme);
		this.add(selectTheme);
		JButton shortcutKeys = new JButton("Shortcut Keys");
		this.add(shortcutKeys);
		this.add(new JLabel(""));
		final JComboBox closeAction = new JComboBox();
		closeAction.addItem("Exit");
		closeAction.addItem("Minimise to system tray");
		this.add(new JLabel("When exit is pressed:"));
		if(exitVal == 0) closeAction.setSelectedIndex(0);
		else closeAction.setSelectedIndex(1);
		this.add(closeAction);
		JButton restore = new JButton("Restore Defaults");
		restore.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {				
				themeVal = 0;
				exitVal = 0;
				selectTheme.setSelectedIndex(0);
				closeAction.setSelectedIndex(0);
			}
		});
		this.add(restore);
		this.add(new JLabel(""));
		JButton cancel = new JButton("Cancel");
		cancel.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {				
				window.dispose();
			}
		});
		JButton apply = new JButton("Apply changes");
		apply.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				themeVal = selectTheme.getSelectedIndex();
				exitVal = closeAction.getSelectedIndex();
				window.dispose();
			}
		});
		this.add(cancel);
		this.add(apply);
		
		
		this.pack();
		this.setVisible(true);
		
	}
}